<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\modules\home\models\Booklist */
/* @var $form yii\widgets\ActiveForm */
//echo "<pre>";
//print_r(\common\components\Tools::getTagList());exit;
?>

<div class="booklist-form">

    <?php $form = ActiveForm::begin(); ?>

    <div class="row">
        <div class="col-md-6">

            <?= $form->field($model, 'cid')->dropDownList($catelist,['value'=>$model->cid]) ?>

            <?= $form->field($model, 'parent_id')->dropDownList($parentlist,['value'=>$model->parent_id]) ?>

            <?= $form->field($model, 'type')->dropDownList(['1' => '单行本', '2' => '多行本']) ?>

            <?php if($model->isNewRecord){ ?>
                <?= $form->field($model, 'number')->textInput(['value' => \common\components\Tools::get_random_code(6,1),'readonly' => true]) ?>
            <?php }?>

            <?= $form->field($model, 'front_title')->textInput(['maxlength' => true]) ?>

            <?= $form->field($model, 'backend_title')->textInput(['maxlength' => true]) ?>

            <?= $form->field($model, 'thumb_img')->textInput(['maxlength' => true]) ?>

            <?php if($model->isNewRecord){ ?>
                <?= $form->field($model, 'cont_num')->textInput(['value' => '0']) ?>
                <?= $form->field($model, 'click_num')->textInput(['value' => '0']) ?>
                <?= $form->field($model, 'zan_num')->textInput(['value' => '0']) ?>
            <?php }else{ ?>
                <?= $form->field($model, 'cont_num')->textInput() ?>

                <?= $form->field($model, 'click_num')->textInput() ?>

                <?= $form->field($model, 'zan_num')->textInput() ?>
            <?php }?>


            <?= $form->field($model, 'intro')->textarea(['rows'=>3]) ?>




        </div>
        <div class="col-md-6">

            <div id="all_attr" style="padding: 10px 0;">
                <?php foreach (\common\components\Tools::getTagList() as $v):?>
                    <?php
                    $attrarr = explode('&',$model->mark);
                    if(!in_array($v['id'],$attrarr)){
                        ?>
                        <span class="single-area" onclick='add_attr(this,"<?=$v['id']?>")' style="background-color: #59B4F9;border: none;display:inline-block;margin-bottom: 5px;padding:4px 12px;color:#fff;cursor: pointer;white-space:nowrap;"><?php echo $v['cont']?></span>
                    <?php }?>
                <?php endforeach;?>
            </div>

            <?= $form->field($model, 'mark')->textInput(['maxlength' => true]) ?>

            <?= $form->field($model, 'remark')->textInput(['maxlength' => true]) ?>

            <?= $form->field($model, 'is_recommend')->dropDownList(['0' => '否', '1' => '是']) ?>

            <?= $form->field($model, 'is_hot')->dropDownList(['0' => '否', '1' => '是']) ?>

            <?= $form->field($model, 'is_over')->dropDownList(['0' => '否', '1' => '是']) ?>

            <?= $form->field($model, 'is_advert')->dropDownList(['1' => '是', '0' => '否']) ?>

            <?= $form->field($model, 'is_free')->dropDownList(['0' => '否', '1' => '是']) ?>

            <?php if($model->isNewRecord){ ?>
                <?= $form->field($model, 'date')->textInput(['maxlength' => true, 'type' => 'date', 'value' => date('Y-m-d')]) ?>
                <?= $form->field($model, 'sort')->textInput(['value' => 0])->label('排序 <span style="color:red">【 数值越大越靠前 】</span>') ?>
            <?php }else{ ?>
                <?= $form->field($model, 'sort')->textInput()->label('排序 <span style="color:red">【 数值越大越靠前 】</span>') ?>
                <?= $form->field($model, 'date')->textInput(['maxlength' => true, 'type' => 'date']) ?>
            <?php }?>

            <?= $form->field($model, 'status')->dropDownList(['1' => '上架', '0' => '下架']) ?>

        </div>
    </div>









    <div class="form-group">
        <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<script>
    function add_attr(con,id) {
        // console.log(id)
        var span = $(con);
        var attribute = $('#booklist-mark');
        var attr = attribute.val();
        if(attr){
            var now = attr+'&'+id;
        }else{
            var now = id;
        }
        attribute.val(now);
        span.remove();
    }
</script>